<?php
session_start();
if(isset($_POST["zoek"])) {
include('printstyle.php');
$taal = $_SESSION['taal'];
require_once('pasmy/dbwaarden.php');
include('french.php');
require_once('funktie.php');
?> 
<h2><div style="text-align: center"><?php echo $dbzoeken[$taal];?></div></h2>
<?php
echo "<br><br>";
 
$mysql_id = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($db, $mysql_id);

//postwaarden();


if(isset($_POST["verder"])) {
	//echo "ik kom van updaten.php<br>";
	$sql = $_SESSION["zoekterm"];
	$waardb = $_SESSION["waardb"];
}
else {

// invoegen einde

if($_POST["yy"] == "-----") { $waardb = "vnzvrn" . $_POST["jaar"]; } else {$waardb = "vnzvrn" . $_POST["yy"];}
if($_POST["yy1"] == "-----") { $waardb = "vnzvrn" . $_POST["jaar"]; } else {$waardb = "vnzvrn" . $_POST["yy1"];}
if($_POST["yy2"] == "-----") { $waardb = "vnzvrn" . $_POST["jaar"]; } else {$waardb = "vnzvrn" . $_POST["yy2"];}

$sql = "Select * from `$waardb`";
if(!empty($_POST["driver"])) {
	$_POST["driver"] = mysql_real_escape_string($_POST["driver"]);
	if ($en != 1) { $ver = " Where "; } else { $ver = "and";}	
	$sql .= "$ver `driver` like  '%$_POST[driver]%'";
	$en = 1;	
	}

if($_POST["nrpl"] != "-----") {
	$_POST["nrpl"] = mysql_real_escape_string($_POST["nrpl"]);
	if ($en != 1) { $ver = " Where "; } else { $ver = "and";}	
	$sql .= "$ver `nrpl` =  '$_POST[nrpl]'";
	$en = 1;	
	}

if($_POST["jj"] !="-----") {
	if($_POST["mm"] < 10) { $_POST["mm"] = "0" . $_POST["mm"]; }
	$datum = $_POST["yy"] . "-" . $_POST["mm"] . "-" . $_POST["jj"];
	
	if ($en != 1) { $ver = " Where "; } else { $ver = "and";}
	$sql .= " $ver `datum` like '$datum'";
	$en = 1;	
	}
if($_POST["jj1"] != "-----") {
	if($_POST["mm1"] < 10) { $_POST["mm1"] = "0" . $_POST["mm1"]; }
	if($_POST["mm2"] < 10) { $_POST["mm2"] = "0" . $_POST["mm2"]; }
	
	$datum1 = $_POST["yy1"] . "-" . $_POST["mm1"] . "-" . $_POST["jj1"];
	$datum2 = $_POST["yy2"] . "-" . $_POST["mm2"] . "-" . $_POST["jj2"];
	
	if ($en != 1) { $ver = " Where "; } else { $ver = "and";}
	$sql .= " $ver `datum` >= '$datum1' and `datum` <= '$datum2'";
	$en = 1;
	
	}
if(!empty($_POST["ref"])) {
	$_POST["ref"] = mysql_real_escape_string($_POST["ref"]);
	if ($en != 1) { $ver = " Where "; } else { $ver = "and";} 
	$sql .= " $ver `ref` like '%$_POST[ref]%'";
	$en = 1;
	}
if(!empty($_POST["client"])) {
	$_POST["client"] = mysql_real_escape_string($_POST["client"]);
	if ($en != 1) { $ver = " Where "; } else { $ver = "and";} 
	$sql .= " $ver `client` like '%$_POST[client]%'";
	$en = 1;
	}
if(!empty($_POST["expedi"])) {
	$_POST["expedi"] = mysql_real_escape_string($_POST["expedi"]);
	if ($en != 1) { $ver = " Where "; } else { $ver = "and";} 
	$sql .= " $ver `expediteur` like '%$_POST[expedi]%'";
	$en = 1;
	}
if(!empty($_POST["laadplaats"])) {
	$_POST["laadplaats"] = mysql_real_escape_string($_POST["laadplaats"]);
	if ($en != 1) { $ver = " Where "; } else { $ver = "and";} 
	$sql .= " $ver `laadplaats` like '%$_POST[laadplaats]%'";
	$en = 1;
	}


if(!empty($_POST["desti"])) {
	$_POST["desti"] = mysql_real_escape_string($_POST["desti"]);
	if ($en != 1) { $ver = " Where "; } else { $ver = "and";} 
	$sql .= " $ver `bestemmeling` like '%$_POST[desti]%'";
	$en = 1;
	}
if(!empty($_POST["ville"])) {
	$_POST["ville"] = mysql_real_escape_string($_POST["ville"]);
	if ($en != 1) { $ver = " Where "; } else { $ver = "and";} 
	$sql .= " $ver `plaats` like '%$_POST[ville]%'";
	$en = 1;
	}
if(!empty($_POST["colis"])) {
	if ($en != 1) { $ver = " Where "; } else { $ver = "and";} 
	$sql .= " $ver `colis` = '$_POST[colis]'";
	$en = 1;
	}
if(!empty($_POST["pal"])) {
	if ($en != 1) { $ver = " Where "; } else { $ver = "and";} 
	$sql .= " $ver `pal` = '$_POST[pal]'";
	$en = 1;
	}
if(!empty($_POST["mp"])) {
	if ($en != 1) { $ver = " Where "; } else { $ver = "and";} 
	$sql .= " $ver `mp` like '%$_POST[mp]%'";
	$en = 1;
	}
if(!empty($_POST["poids"])) {
	if ($en != 1) { $ver = " Where "; } else { $ver = "and";} 
	$sql .= " $ver `poids` = '$_POST[poids]'";
	$en = 1;
	}
if(!empty($_POST["prix"])) {
	if ($en != 1) { $ver = " Where "; } else { $ver = "and";} 
	$sql .= " $ver `prijs` like '%$_POST[prix]%'";
	$en = 1;
	}
if(!empty($_POST["week"])) {
	if ($en != 1) { $ver = " Where "; } else { $ver = "and";} 
	$sql .= " $ver `week` = '$_POST[week]'";
	$en = 1;
	}
	
 

$sql = $sql . " order by `datum`,`ligne`";
$_SESSION["zoekterm"] = $sql;
$_SESSION["waardb"] = $waardb;
}


?>

<table border="1" width="100%" align="center">
<tr>
<td class="delsaux2"><?php echo $datum[$taal];?></td>
<td class="delsaux2"><?php echo $referentie[$taal];?></td>
<td class="delsaux2">CMR</td>
<td class="delsaux2"><?php echo $klant[$taal];?></td>
<td class="delsaux2"><?php echo $verzender[$taal];?></td>
<td class="delsaux2"><?php echo $laplaats[$taal];?></td>
<td class="delsaux2"><?php echo $bestemmeling[$taal];?></td>
<td class="delsaux2"><?php echo $plaats[$taal];?></td>
<td class="delsaux2">Col</td>
<td class="delsaux2"><?php echo $pals[$taal];?></td>
<td class="delsaux2"><?php echo $vloerm[$taal];?></td>
<td class="delsaux2"><?php echo $gewicht[$taal];?></td>
<td class="delsaux2"><?php echo $pprijs[$taal];?></td>
<td class="delsaux2">Gasoil</td>
<td class="delsaux2">Chauffeur</td>
<td class="delsaux2">Camion</td>
<td class="delsaux2">Ligne</td>

<!-- <td class="delsaux2"><?php echo $opmerkingen[$taal];?></td> -->
<?php
if(isset($_POST["remark"])) {
	echo "<td class='delsaux2'>$opmerkingen[$taal]</td>";
	}
if($_SESSION['login'] < "22") {
		 echo "<td class='delsaux2'>Update</td>";
}
if($_SESSION['login'] < "17") {
		 echo "<td class='delsaux2'>Delete</td>";
}
 
?>
</tr>

<?php
if($_SESSION['login'] == "0") {
echo "<b>sql = $sql<b></br><br />";	
}
$res = mysql_query($sql, $mysql_id);
/*if(empty($row[0])) { echo "<tr><td colspan='14'><br /><div style='text-align: center'>
<b>Aucun document ne correspond aux termes de recherche sp&eacute;cifi&eacute;s </b></div><br /></td></tr>";}*/
$dag = "0000-00-00";
while ($row = mysql_fetch_row($res)) {
	if($row[0] > $dag) {$nombre++;$dag = $row[0];}
	if ($nombre%2 == 1)
    $klasse = "#FFFFEA";
    
  else
    $klasse = "#D0FFFF";
   
	
	$dagdatum = explode("-",$row[0]);
	$tota = $tota + $row[10];
	$totag = $totag + $row[17];
	
	$camion = $row[18];
	//$kleurtje = $klasse;
	switch($camion) {
		case "447CKA59":
			$kleurtje = "#FF7D5C";
		break;
		case "1-BFQ 358":
			$kleurtje = "yellow";
		break;
		case "3285YC74":
			$kleurtje = "#E8D18D";
		break;
		case "KLL 248":
			$kleurtje = "#6CFFFF";
		break;
		case "Affretement":
			$kleurtje = "red";
		break;
		default: 
			$kleurtje = $klasse;
	}	
	//echo "row18 = |$row[18]| en kleurtje = $kleurtje en week = $_POST[week]<br>";
	
	if(empty($row[16])) {$row[16]="&nbsp;";}
	 echo "<tr bgcolor = '$klasse'>
	<td class = 'zones'>$dagdatum[2]-$dagdatum[1]-$dagdatum[0]</td>
	<td class = 'zones'>$row[1]</td>
	<td class = 'zones'>$row[16]</td>
	<td class = 'zones'><div style='text-align: center'>$row[2]</div></td>
	<td class = 'zones'><div style='text-align: center'>$row[3]</div></td>

	<td class = 'zones'><div style='text-align: center'>$row[15]</div></td>
	
	<td class = 'zones'><div style='text-align: center'>$row[4]</div></td>
	<td class = 'zones'><div style='text-align: center'>$row[5]</div></td>
	<td class = 'zones'><div style='text-align: center'>$row[6]</div></td>
	<td class = 'zones'><div style='text-align: center'>$row[7]</div></td>
	<td class = 'zones'><div style='text-align: center'>$row[8]</div></td>
	<td class = 'zones'><div style='text-align: center'>$row[9]</div></td>
	<td class = 'zones'><div style='text-align: center'>$row[10]</div></td>
	<td class = 'zones'><div style='text-align: center'>$row[17]</div></td>
	<td class = 'zones'><div style='text-align: center'>$row[12]</div></td>";
	echo "<td class = 'zones' bgcolor='$kleurtje'><div style='text-align: center'>$row[18]</div></td>";
	echo "<td class = 'zones' bgcolor='$kleurtje'><div style='text-align: center'>$row[19]</div></td>";
	if(isset($_POST["remark"])) {
	echo "<td class='zones'>$row[11]</td>";
	}
		
		 
	if($_SESSION['login'] < "20") {

		echo "<td class = 'zones'><a href='pdt.php?nr=$row[14]&jaren=$waardb' class = 'linkblue'>Update</a></td>";
	}
	if($_SESSION['login'] < "15") {
		echo "<td class = 'zones'><a href='deleten.php?nr=$row[14]&jaren=$waardb' class = 'linkred'>Delete</a></td>";
		
	}
	echo "</tr>";
	

}
mysql_free_result($res);
echo "<tr><td colspan='12'>&nbsp;</td><td class = 'delsaux'>$tota</td>";
echo "<td class = 'delsaux'>$totag</td><td colspan='5'>&nbsp;</td></tr>";
$glob = $tota + $totag;
echo "<tr><td colspan='12'>&nbsp;</td><td class = 'delsaux2' colspan='2'>$glob</td><td colspan='5'>&nbsp;</td></tr>";
echo "</table>";

}
//echo "zoekterm = $zoekterm<br>";
?>
<br /><br />
<font size="5"><strong><a href="zoeken.php" class="linkblue"><div style="text-align: center">Retour</div></a></strong></font>
